home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / MM3Tp.sea Folder / Made by Marksman / Sources / mm / mmMainMM_Demo.p < prev    next >
Text File  |  1994-01-16  |  23KB  |  648 lines

  1. program mmMainMM_Demo;
  2. { mmMainMM_Demo }
  3.  
  4. {    
  5.     Program name:  mmMainMM_Demo  
  6.     Function:  This is the main module for this program.  
  7.     History: 1/16/94 Original by George Cossey
  8.  
  9.    }
  10.  
  11.     uses
  12.         Printing, Folders, Sound,mmCommonMM_Demo,CommonMM_Demo,{}
  13.         UInitExitMM_Demo,UeventsMM_Demo,{}
  14.         mmPA_My_Alert,
  15.         {}
  16.         mmD_My_Modal,
  17.         {}
  18.         mmMD_My_Movable_Moda,
  19.         mmMD_My_Modeless,
  20.         mmMD_About_Demo,
  21.         {}
  22.         UMy_basic_window,
  23.         UFloating_window,
  24.         {}
  25.         mmW_My_basic_window,
  26.         mmW_Floating_window,
  27.         {}
  28.         mmMenuMM_Demo;
  29.  
  30.  
  31. var
  32. DoIt:Boolean;                                { Flag saying an event is ready }
  33. code:integer;                                { Determine event type }
  34. whichWindow:WindowPtr;                        { See which window for event }
  35. mResult:longint;                            { Menu list and item selected values }
  36. theMenu,theItem:integer;                    { Menu list and item selected }
  37. Is_A_Dialog:Boolean;                        { Flag for modless dialogs }
  38. charCode, itemHit:integer;                    { For modeless dialogs}
  39. ch:char;                                    { Key pressed in Ascii }
  40. DoTheModelessEvent, CmdDown:Boolean;        { For modeless dialogs}
  41. thePeeked:WindowPeek;                        { For modeless dialogs}
  42.  
  43.  
  44. { ======================================================= }
  45.  
  46. { Routine: WNEIsImplemented }
  47. { Purpose: See if the MultiFinder trap, WaitNextEvent, is available }
  48.  
  49. function IsWNEIsImplemented:Boolean;                    { See if WaitNextEvent is available }
  50. const
  51.     WNETrapNumber = $A860;                    { The expected trap number }
  52.     kGestaltTrapID = $A1AD;                    { The expected trap number }
  53. var
  54.     theWorld:SysEnvRec;                        { Environment record }
  55.     discardError:OSErr;                        { Error code returned }
  56.     theWNEIsImplemented:Boolean;            { Value to return }
  57.     result:longint;                            { Value returned }
  58.  
  59.  
  60. begin
  61. Black_ForeColor.red := $0000;  Black_ForeColor.green := $0000;  Black_ForeColor.blue := $0000;  { Get black color }
  62. White_BackColor.red := $FFFF;  White_BackColor.green := $FFFF;  White_BackColor.blue := $FFFF;  { Get white color }
  63.  
  64. Has.ColorQD := FALSE;                                { Init to no color QuickDraw }
  65. Has.FPU := FALSE;                                    { Init to no floating point chip }
  66. Has.AppleEvents := FALSE;                            { Whether AppleEvents are available }
  67. Has.AliasMgr := FALSE;                                { Whether AliasMgr is available }
  68. Has.EditionMgr := FALSE;                                { Whether EditionMgr is available }
  69. Has.Gestalt := FALSE;                                { Whether Gestalt is available }
  70. Has.NewStdFile := FALSE;                                { Whether NewStdFile is available }
  71. Has.PPCToolbox := FALSE;                                { Whether PPCToolbox is available }
  72. Has.QuickDraw32Bit := FALSE;                            { Whether 32Bit QuickDraw is available }
  73. InTheForeground := TRUE;                                { Init to a foreground app }
  74.  
  75. discardError := SysEnvirons(1,theWorld);            { Check how old this system is }
  76. if (theWorld.machineType < 0) then                    { Negative means really old }
  77.     theWNEIsImplemented := FALSE                        { Really old ROMs, no WNE possible }
  78. else
  79.     begin
  80.     theWNEIsImplemented := CheckTrapAvailable(WNETrapNumber,ToolTrap);{ See if trap is there }
  81.     Has.ColorQD := theWorld.hasColorQD;                { Flag for Color QuickDraw being available }
  82.     Has.FPU := theWorld.hasFPU;                        { Flag for Floating Point Math Chip being available }
  83.     Has.Gestalt := CheckTrapAvailable(kGestaltTrapID, ToolTrap);{ Whether Gestalt is available }
  84.     if (Has.Gestalt) then                            { Do if Gestalt is available }
  85.         begin
  86.         discardError := Gestalt(gestaltAliasMgrAttr,result);
  87.         if ((discardError = 0) and (BAND(result, BSL($00000001, gestaltAliasMgrPresent)) <> 0)) then
  88.             Has.AliasMgr := TRUE;
  89.  
  90.         discardError := Gestalt(gestaltEditionMgrAttr,result);
  91.         if ((discardError = 0) and (BAND(result, BSL($00000001, gestaltEditionMgrPresent)) <> 0)) then
  92.             Has.EditionMgr := TRUE;
  93.  
  94.         discardError := Gestalt(gestaltAppleEventsAttr,result);
  95.         if ((discardError = 0) and (BAND(result, BSL($00000001, gestaltAppleEventsPresent)) <> 0)) then
  96.             Has.AppleEvents := TRUE;
  97.  
  98.         discardError := Gestalt(gestaltPPCToolboxAttr,result);
  99.         if ((discardError = 0) and (BAND(result, BSL($00000001, gestaltPPCToolboxPresent)) <> 0)) then
  100.             Has.PPCToolbox := TRUE;
  101.  
  102.         discardError := Gestalt(gestaltQuickdrawVersion,result);
  103.         if ((discardError = 0) and (BAND(result, BSL($00000001, gestalt32BitQD)) <> 0)) then
  104.             Has.QuickDraw32Bit := TRUE;
  105.  
  106.         discardError := Gestalt(gestaltStandardFileAttr,result);
  107.         if ((discardError = 0) and (BAND(result, BSL($00000001, gestaltStandardFile58)) <> 0)) then
  108.             Has.NewStdFile := TRUE;
  109.         end;
  110.     end;
  111.     
  112. IsWNEIsImplemented := theWNEIsImplemented;
  113. end;
  114.  
  115. { ======================================================= }
  116.  
  117. { Routine: Handle_User_Event }
  118. { Purpose: Check for user events }
  119.  
  120. procedure Handle_User_Event;                        { Check for user events }
  121. var
  122.     TheUserEvent:UserEventRec;                    { The user event }
  123.  
  124.  
  125. begin
  126. GetUserEvent(@TheUserEvent);                        { Check for any user events }
  127. if (TheUserEvent.ID <> UserEvent_None) then        { Only do if we have any }
  128.     begin
  129.  
  130.     case (TheUserEvent.ID) of                    { Key off the Event ID }
  131.         UserEvent_Open_Window:                     { Open a Window or Modeless dialog }
  132.             begin
  133.             case (TheUserEvent.ID2) of            { Do the appropiate window }
  134.                 -1:begin end;
  135.                 ResA_My_Alert:
  136.                     PA_My_Alert;        { Open this alert }
  137.                 ResD_My_Modal:
  138.                     MPD_My_Modal;        { Open this modal dialog }
  139.                 ResD_My_Movable_Moda:
  140.                     Open_My_Movable_Moda;    { Open this modeless dialog }
  141.                 ResD_My_Modeless:
  142.                     Open_My_Modeless;    { Open this modeless dialog }
  143.                 ResD_About_Demo:
  144.                     Open_About_Demo;    { Open this modeless dialog }
  145.                 ResW_My_basic_window: 
  146.                     Open_My_basic_window;    { Open this window }
  147.                 ResW_Floating_window: 
  148.                     Open_Floating_window;    { Open this window }
  149.                 otherwise                        { Handle others }
  150.                     begin
  151.                     end;
  152.                 end;                            { End of the switch }
  153.             end;
  154.  
  155.         UserEvent_Close_Window:                 { Close a Window or Modeless dialog }
  156.             begin
  157.             case (TheUserEvent.ID2) of            { Do the appropiate window }
  158.                 -1:begin end;
  159.                 ResD_My_Movable_Moda:
  160.                     Close_My_Movable_Moda(Rec_My_Movable_Moda.theDialog);{ Close this modeless dialog }
  161.                 ResD_My_Modeless:
  162.                     Close_My_Modeless(Rec_My_Modeless.theDialog);{ Close this modeless dialog }
  163.                 ResD_About_Demo:
  164.                     Close_About_Demo(Rec_About_Demo.theDialog);{ Close this modeless dialog }
  165.                 ResW_My_basic_window: 
  166.                     Close_My_basic_window(WindowPtr(-1));    { Close this window }
  167.                 ResW_Floating_window: 
  168.                     Close_Floating_window(WindowPtr(-1));    { Close this window }
  169.                 otherwise                            { Handle others }
  170.                     begin
  171.                     end;
  172.                 end;                                { End of the switch }
  173.             end;
  174.  
  175.         otherwise                                    { Not standard, must be program specific }
  176.             begin
  177.             Handle_UserEvent(@TheUserEvent);            { Let program specific handle it }
  178.             end;
  179.         end;                                        { End of switch }
  180.     end;
  181. end;
  182.  
  183. { ======================================================= }
  184.  
  185. { Routine: DoKeyEvent }
  186. { Purpose: Handle a key pressed }
  187.  
  188. procedure DoKeyEvent;                                { Handle key presses }
  189. var
  190.     charCode:integer;                                { Key code }
  191.     ch:char;                                        { Key pressed in Ascii }
  192.     mResult:longint;                                { Menu list and item, if a command key }
  193.     theMenu,theItem:integer;                        { Menu list and item, if command key }
  194.  
  195.  
  196. begin
  197. if (HandleKey(myEvent)) then                        { Allow for special key handling }
  198.     begin
  199.     charCode := BAND(myEvent.message,charCodeMask);    { Get the character }
  200.     ch := char(charCode);                                    { Change it to ASCII }
  201.  
  202.     if (BAND(myEvent.modifiers,cmdKey) <> 0) then        { See if Command key is down }
  203.         begin
  204.         U_EnableMenus;                            { Let us in to enable and disable menus}
  205.         mResult := MenuKey(ch);                        { See if a menu selection }
  206.         theMenu := HiWord(mResult);                    { Get the menu list number }
  207.         theItem := LoWord(mResult);                    { Get the menu item number }
  208.         if (theMenu <> 0) then                            { See if a list was selected }
  209.             Handle_My_Menu(theMenu,theItem);        { Do the menu selection }
  210.  
  211.         if (((ch = 'x') or (ch = 'X')) and (theInput <> NIL)) then
  212.             TECut(theInput)                        { Handle a Cut in a TE area }
  213.         else if (((ch = 'c') or (ch = 'C')) and (theInput <> NIL)) then
  214.             TECopy(theInput)                        { Handle a Copy in a TE area }
  215.         else if (((ch = 'v') or (ch = 'V')) and (theInput <> NIL)) then
  216.             TEPaste(theInput);                        { Handle a Paste in a TE area }
  217.         end
  218.     else if (theInput <> NIL) then
  219.         TEKey(ch,theInput);                            { Place the normal key stroke }
  220.     end;
  221. end;
  222.  
  223. { ======================================================= }
  224.  
  225. { Routine: DoDiskEvent }
  226. { Purpose: Handle a diskette inserted }
  227.  
  228. procedure DoDiskEvent;                                { Handle disk inserted }
  229. var
  230.     theError:integer;                                    { Error returned from mount }
  231.  
  232.  
  233. begin
  234. if (HandleDisk(myEvent)) then                            { Allow for special disk inserted handling }
  235.     begin
  236.     if (HiWord(myEvent.message) <> noErr) then            { See if a diskette mount error }
  237.         begin
  238.         myEvent.where.h := ((screenBits.bounds.right - screenBits.bounds.left) div 2) - (304 div 2);{ Center horz }
  239.         myEvent.where.v := ((screenBits.bounds.bottom - screenBits.bounds.top) div 3) - (104 div 2);{ Top 3ed vertically }
  240.         InitCursor;                                { Make sure it has an arrow cursor }
  241.         theError := DIBadMount(myEvent.where, myEvent.message);{ Let the OS handle the diskette }
  242.         end;
  243.     end;
  244. end;
  245.  
  246. { ======================================================= }
  247.  
  248. { Routine: DoZoom }
  249. { Purpose: Handle a window zoom }
  250.  
  251. procedure DoZoom(whichWindow:WindowPtr;code:integer);    { Handle a window zoom }
  252. var
  253.     OldRect:Rect;                                    { Window rect before the zoom }
  254.     myPt:Point;                                        { Point for tracking zoom box }
  255.     theRefCon:longint;                                    { Refcon with layer masked off }
  256.  
  257.  
  258. begin
  259. if (not(Doing_MovableModal)) then                        { Select proper window }
  260.     begin
  261.     if (whichWindow <> NIL)    then                        { See if we have a legal window }
  262.         begin
  263.         SetPort(whichWindow);                        { Get ready to draw in this window }
  264.  
  265.         myPt := myEvent.where;                        { Get mouse position }
  266.         GlobalToLocal(myPt);                        { Make it relative }
  267.  
  268.         OldRect := whichWindow^.portRect;            { Save the rect before resizing }
  269.  
  270.         if (TrackBox(whichWindow, myPt, code)) then        { Zoom it }
  271.             begin
  272.             ZoomWindow(whichWindow, code, TRUE);    { Resize to result }
  273.             EraseRect(whichWindow^.portRect);        { Make sure we update the whole window effectively }
  274.             InvalRect(whichWindow^.portRect);        { Tell ourselves to update, redraw, the window contents }
  275.             theRefCon := GetWRefCon(whichWindow);    { Get the refcon }
  276.             theRefCon := BAND(theRefCon,$00FFFFFF);        { Mask the layer out }
  277.  
  278.             case (theRefCon) of                        { Do the appropiate window }
  279.                 -1:begin end;
  280.                 ResW_My_basic_window:
  281.                     Resized_My_basic_window(OldRect, whichWindow);{ Resized this window }
  282.  
  283.                 otherwise                            { Handle others }
  284.                     U_DoZoom(OldRect,whichWindow);    { Allow user to handle others }
  285.                 end;
  286.             Mk_HiliteWindow(whichWindow);            { Hilite it again }
  287.             end;
  288.         end;
  289.     end;
  290. end;
  291.  
  292. { ======================================================= }
  293.  
  294. { Routine: DoDrag }
  295. { Purpose: Drag a window around }
  296.  
  297. procedure DoDrag(whichWindow:WindowPtr);
  298. var
  299.     OldRect:Rect;                                { Window rect before the drag }
  300.     tempRect:Rect;                                { temporary rect }
  301.     theRefCon:longint;                            { Refcon with layer masked off }
  302.  
  303.  
  304. begin
  305. if ((not(Doing_MovableModal)) or (Doing_MovableModal and (whichWindow = FrontWindow))) then{ See if OK to drag }
  306.     begin
  307.     OldRect := whichWindow^.portRect;            { Save the rect before resizing }
  308.  
  309.     if (not(Doing_MovableModal)) then                    { Select proper window }
  310.         Mk_HiliteWindow(whichWindow);
  311.     SetRect(tempRect, -32000, -32000, 32000, 32000);
  312.     Mk_DragWindow(whichWindow,myEvent.where,tempRect);{ Drag the window }
  313.  
  314.     theRefCon := GetWRefCon(whichWindow);        { Get the refcon }
  315.     theRefCon := BAND(theRefCon,$00FFFFFF);        { Mask the layer out }
  316.     case (theRefCon) of                            { Do the appropiate window }
  317.         -1:begin end;
  318.         ResD_My_Movable_Moda:
  319.             Moved_My_Movable_Moda(OldRect,whichWindow);    { Moved this modeless dialog }
  320.         ResD_My_Modeless:
  321.             Moved_My_Modeless(OldRect,whichWindow);    { Moved this modeless dialog }
  322.         ResD_About_Demo:
  323.             Moved_About_Demo(OldRect,whichWindow);    { Moved this modeless dialog }
  324.         ResW_My_basic_window:
  325.             U_MovedMy_basic_window(OldRect,whichWindow);{ Moved this window }
  326.         ResW_Floating_window:
  327.             U_MovedFloating_window(OldRect,whichWindow);{ Moved this window }
  328.  
  329.         otherwise                                { allow other buttons, trap for debug }
  330.             U_Moved(OldRect,whichWindow);        { Allow user to handle others }
  331.         end;                                        { end of switch }
  332.     end;
  333. end;
  334.  
  335. { ======================================================= }
  336.  
  337. { Routine: DoGoAway }
  338. { Purpose: Close a window }
  339.  
  340. procedure DoGoAway(whichWindow:WindowPtr);
  341. var
  342.     theRefCon:longint;                                { Refcon with layer masked off }
  343.  
  344.  
  345. begin
  346. if (not(Doing_MovableModal)) then                        { Select proper window }
  347.     begin
  348.     if (TrackGoAway(whichWindow,myEvent.where)) then    { See if mouse released in GoAway box }
  349.         begin
  350.         theRefCon := GetWRefCon(whichWindow);    { Get the refcon }
  351.         theRefCon := BAND(theRefCon,$00FFFFFF);        { Mask the layer out }
  352.         case (theRefCon) of                        { Do the appropiate window }
  353.             -1:begin end;
  354.             ResD_My_Movable_Moda:
  355.                 Close_My_Movable_Moda(whichWindow);    { Close this modeless dialog }
  356.             ResD_My_Modeless:
  357.                 Close_My_Modeless(whichWindow);    { Close this modeless dialog }
  358.             ResD_About_Demo:
  359.                 Close_About_Demo(whichWindow);    { Close this modeless dialog }
  360.             ResW_My_basic_window:
  361.                 Close_My_basic_window(whichWindow);    { Close this window }
  362.             ResW_Floating_window:
  363.                 Close_Floating_window(whichWindow);    { Close this window }
  364.  
  365.             otherwise                            { allow other buttons, trap for debug }
  366.                 U_GoAway(whichWindow);            { Allow user to handle others }
  367.             end;                                    { end of switch }
  368.         end;
  369.     end;
  370. end;
  371.  
  372. { ======================================================= }
  373.  
  374. { Routine: DoInContent }
  375. { Purpose: Pressed in the content area }
  376.  
  377. procedure DoInContent(whichWindow:WindowPtr;var myEvent:EventRecord);
  378. var
  379.     theRefCon:longint;                                { Refcon with layer masked off }
  380.  
  381.  
  382. begin
  383. if (not(Doing_MovableModal)) then                        { Select proper window }
  384.     begin
  385.     if (Mk_Is_FrontWindow(whichWindow) = false)    then { See if already selected or not, in front if selected }
  386.         Mk_HiliteWindow(whichWindow)
  387.     else
  388.         begin
  389.         SetPort(whichWindow);                    { Get ready to draw in this window }
  390.         Mk_HiliteWindow(whichWindow);
  391.         theRefCon := GetWRefCon(whichWindow);    { Get the refcon }
  392.         theRefCon := BAND(theRefCon,$00FFFFFF);        { Mask the layer out }
  393.  
  394.         case (theRefCon) of                        { Do the appropiate window }
  395.             -1:begin end;
  396.             ResW_My_basic_window:
  397.                 Do_My_basic_window(myEvent);        { Handle this window }
  398.             ResW_Floating_window:
  399.                 Do_Floating_window(myEvent);        { Handle this window }
  400.  
  401.             otherwise                            { allow other buttons, trap for debug }
  402.                 U_InContent(myEvent,whichWindow);    { Allow user to handle others }
  403.             end;                                    { end of switch }
  404.         end;
  405.     end;
  406. end;
  407.  
  408. { ======================================================= }
  409.  
  410. { Routine: DoUpdate }
  411. { Purpose: Got an update event }
  412.  
  413. procedure DoUpdate;
  414. var
  415.     whichWindow:WindowPtr;                        { See which window for event }
  416.     theRefCon:longint;                            { Refcon with layer masked off }
  417.  
  418.  
  419. begin
  420. whichWindow := WindowPtr(myEvent.message);        { Get the window the update is for }
  421.  
  422. BeginUpdate(whichWindow);                        { Set the clipping to the update area }
  423. theRefCon := GetWRefCon(whichWindow);            { Get the refcon }
  424. theRefCon := BAND(theRefCon,$00FFFFFF);                { Mask the layer out }
  425. case (theRefCon) of                                { Do the appropiate window }
  426.     -1:begin end;
  427.     ResW_My_basic_window:
  428.         Update_My_basic_window(whichWindow);        { Update this window }
  429.     ResW_Floating_window:
  430.         Update_Floating_window(whichWindow);        { Update this window }
  431.  
  432.     otherwise                                    { allow other buttons, trap for debug }
  433.         U_Update(whichWindow);                    { Allow user to handle others }
  434.     end;                                            { end of switch }
  435. EndUpdate(whichWindow);                            { Return to normal clipping area }
  436. end;
  437.  
  438. { ======================================================= }
  439. { ======================================================= }
  440.  
  441. { Start of main body }
  442. begin
  443. MoreMasters;                                    { This reserves space for more handles }
  444. MaxApplZone;                                    { Give us room for memory allocation }
  445. InitCursor;                                        { Make an arrow cursor }
  446.  
  447. doneFlag := FALSE;                                { Do not exit program yet }
  448.  
  449. Init_My_Menus;                                    { Initialize menu bar }
  450.  
  451. theInput := nil;                                { Init to no text edit selection active }
  452.  
  453. SleepValue := 40;                                { Set sleep value }
  454. WNE := IsWNEIsImplemented;                        { See if WaitNextEvent is available }
  455.  
  456. UserEventList := nil;                            { No user events yet }
  457.  
  458. cursorRgn := NewRgn;                            { Cursor region for WaitNextEvent }
  459.  
  460. Printing.hPrint := nil;                            { Init to no print record yet }
  461. Printing.PrinterIsOpen := false;                { We are not printing yet }
  462.  
  463. U_InitPreferences;                                { Set default preferences }
  464.  
  465. InitA_My_Alert;                            { Initialize Alert, My Alert }
  466. InitD_My_Modal;                            { Initialize Modal Dialog, My Modal }
  467. Init_My_Movable_Moda;                            { Initialize Modeless Dialog, My Movable Modal }
  468. Init_My_Modeless;                            { Initialize Modeless Dialog, My Modeless }
  469. Init_About_Demo;                            { Initialize Modeless Dialog, About Demo }
  470. Init_My_basic_window;                            { Initialize Window, My basic window }
  471. Init_Floating_window;                            { Initialize Window, Floating window }
  472.  
  473. Mk_ClearLayers;                                { Init layer array }
  474. Doing_MovableModal := false;                        { Not currently doing a movable modal }
  475.  
  476. ApplInitMM_Demo;                        { Handle extra program initialization }
  477.  
  478. GetPreferences;                                { Get preferences }
  479.  
  480.  
  481. repeat
  482.     ApplLoopMM_Demo;                            { Hook into the main loop }
  483.  
  484.     Handle_User_Event;                                { Check for user events }
  485.  
  486.     if (theInput <> NIL) then                        { See if a TE is active }
  487.         TEIdle(theInput);                            { Blink the cursor if everything is ok }
  488.  
  489.     if (WNE) then                                    { See if do the MultiFinder way }
  490.         DoIt := WaitNextEvent(everyEvent,myEvent,SleepValue,cursorRgn)    { Wait for an event }
  491.     else
  492.         begin
  493.         SystemTask;                                { For support of desk accessories }
  494.         DoIt := GetNextEvent(everyEvent,myEvent);    { See if an event is ready }
  495.         end;
  496.  
  497.     ApplEventMM_Demo(DoIt,myEvent);        { Let us at the event first }
  498.  
  499.     if (DoIt) then                                    { If event then... }
  500.         begin
  501.         Is_A_Dialog := IsDialogEvent(myEvent);        { See if a modeless dialog event }
  502.         if (Is_A_Dialog) then                            { Handle a dialog event }
  503.             begin
  504.              if (myEvent.what = updateEvt) then        { Handle the update of a Modeless Dialog }
  505.                 begin
  506.                 whichWindow := WindowPtr(myEvent.message); { Get the window the update is for }
  507.                 BeginUpdate(whichWindow);            { Set update clipping area }
  508.                 Update_My_Movable_Moda(whichWindow);    { Update Modeless Dialog, My Movable Modal }
  509.                 Update_My_Modeless(whichWindow);    { Update Modeless Dialog, My Modeless }
  510.                 Update_About_Demo(whichWindow);    { Update Modeless Dialog, About Demo }
  511.                 EndUpdate(whichWindow);                { Return to normal clipping area }
  512.                 end
  513.             else
  514.                 begin
  515.                 DoTheModelessEvent := TRUE;            { Go ahead and do it so far }
  516.  
  517.                 if (myEvent.what = keyDown) then         { Check the key down, for a command key event }
  518.                     begin
  519.                     CmdDown := Boolean(BAND((myEvent.modifiers div cmdKey),1));{ Get the command key state }
  520.                     charCode := BAND(myEvent.message,charCodeMask);    { Get the character }
  521.                     ch := char(charCode);                    { Change it to ASCII }
  522.  
  523.                     if ((charCode = 13) or (charCode = 3)) then    { CR or Enter }
  524.                         DoTheModelessEvent := TRUE;    { Handle the default selection }
  525.  
  526.                     if (CmdDown) then            { Handle if the command key was down }
  527.                         begin
  528.                         U_EnableMenus;            { Let us in to enable and disable menus}
  529.                         mResult := MenuKey(ch);        { See if a menu selection }
  530.                         theMenu := HiWord(mResult);    { Get the menu list number }
  531.                         theItem := LoWord(mResult);    { Get the menu item number }
  532.                         if (theMenu <> 0) then        { See if a list was selected }
  533.                             Handle_My_Menu(theMenu,theItem); { Do the menu selection }
  534.  
  535.                         whichWindow := FrontWindow; { Get the front window }
  536.                         if ((ch = 'x') or (ch = 'X')) then    { Handle a CUT }
  537.                             DlgCut(whichWindow)
  538.                         else if ((ch = 'c') or (ch = 'C')) then    { Handle a COPY }
  539.                             DlgCopy(whichWindow)
  540.                         else if ((ch = 'v') or (ch = 'V')) then    { Handle a PASTE }
  541.                             DlgPaste(whichWindow);
  542.  
  543.                         DoTheModelessEvent := FALSE;{ We handled the command key }
  544.                         end;
  545.                     end;
  546.  
  547.                 if (DoTheModelessEvent) then { Do we handle it? }
  548.                     begin
  549.                     if ((DialogSelect(myEvent,whichWindow,itemHit)) or (myEvent.what = mouseDown) or (myEvent.what = keyDown)) then { Ck if do it }
  550.                         begin
  551.                         Do_My_Movable_Moda(myEvent,whichWindow,itemHit);    { Handle the Modeless Dialog, My Movable Modal }
  552.                         Do_My_Modeless(myEvent,whichWindow,itemHit);    { Handle the Modeless Dialog, My Modeless }
  553.                         Do_About_Demo(myEvent,whichWindow,itemHit);    { Handle the Modeless Dialog, About Demo }
  554.                         end;
  555.                     end;
  556.                 end;
  557.             end
  558.         else
  559.             begin
  560.  
  561.             case (myEvent.what)    of                { Decide type of event }
  562.                 mouseDown :                { Mouse button pressed }
  563.                     begin
  564.                     code := FindWindow(myEvent.where,whichWindow);{ Get which window the event happened in }
  565.  
  566.                     case (code)    of            { Decide type of event again }
  567.                         inMenuBar :        { In the menubar }
  568.                             begin
  569.                             U_EnableMenus;                    { Let us in to enable and disable menus}
  570.                             mResult := MenuSelect(myEvent.where);{ Do menu selection }
  571.                             theMenu := HiWord(mResult);            { Get the menu list number }
  572.                             theItem := LoWord(mResult);            { Get the menu list item number }
  573.                             Handle_My_Menu(theMenu,theItem);    { Handle the menu }
  574.                             end;
  575.  
  576.                         inDrag :        { In window drag area }
  577.                             DoDrag(whichWindow);{ Go drag the window }
  578.  
  579.                         inZoomIn,inZoomOut :    { In window zoom area }
  580.                             DoZoom(whichWindow,code);{ Go zoom the window }
  581.  
  582.                         inGoAway :        { In window goaway area }
  583.                             DoGoAway(whichWindow);{ Handle the goaway button }
  584.  
  585.                         inContent :    { In window  contents }
  586.                             DoInContent(whichWindow,myEvent);{ Handle the hit inside a window }
  587.  
  588.                         inSysWindow :    { See if a DA selection }
  589.                             SystemClick(myEvent,whichWindow);{ Let other programs in }
  590.  
  591.                         otherwise            { Handle others }
  592.                             begin
  593.                             end;            { End of otherwise }
  594.                         end;                    { End of code case }
  595.                     end;                    { End of MouseDown }
  596.  
  597.                 keyDown,autoKey:                { and auto repeats }
  598.                     DoKeyEvent;            { Get the key and handle it }
  599.  
  600.                 updateEvt :            { Update event for a window }
  601.                     DoUpdate;                { Handle the update }
  602.  
  603.                 diskEvt :                { Disk inserted event }
  604.                     DoDiskEvent;            { Handle a disk event }
  605.  
  606.                 activateEvt :            { Window activated event }
  607.                     DoActivate;            { Handle the activation }
  608.  
  609.                 osEvt:                    { OS event }
  610.                     DoOSEvent(myEvent);    { Handle the activation }
  611.  
  612.                 otherwise                    { Used for debugging, to see what other events are coming in }
  613.                     begin
  614.                     end;                    { End of otherwise }
  615.  
  616.                 end;                            { End of case }
  617.  
  618.             end;
  619.         end
  620.     else
  621.         begin
  622.         whichWindow := FrontWindow;        { Get the current front window }
  623.         if (whichWindow <> NIL)    then            { See if we have a window }
  624.             begin
  625.             thePeeked := WindowPeek(whichWindow);        { Peek inside, look for dialog }
  626.             if (thePeeked^.windowKind = dialogKind) then    { DialogSelect will crash if no dialogs }
  627.                 begin
  628.                 if (DialogSelect(myEvent,whichWindow,itemHit)) then { Blink cursor in modeless TEs }
  629.                     begin
  630.                     end;
  631.                 end;
  632.             end;
  633.         end;
  634.   until ( doneFlag );                            { End of the event loop }
  635.  
  636. ApplExitMM_Demo;                    { Handle extra program termination code }
  637.  
  638. Close_My_Movable_Moda(Rec_My_Movable_Moda.theDialog);{ Close this modeless dialog }
  639. Close_My_Modeless(Rec_My_Modeless.theDialog);{ Close this modeless dialog }
  640. Close_About_Demo(Rec_About_Demo.theDialog);{ Close this modeless dialog }
  641. Close_My_basic_window(WindowPtr(-1));        { Close this window }
  642. Close_Floating_window(WindowPtr(-1));        { Close this window }
  643.  
  644. SetPreferences;                                { Set new preferences }
  645.  
  646.  
  647. end.
  648.